<extend name="Index/index" />
<block name="myjs">
    
</block> 
<block name="nav1">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">Admin</a>
        </li>
        <li class="active">订单管理表</li>
    </ul><!-- .breadcrumb -->
</block>

<block name="nav2">
        <h1>
            订单管理表
        </h1>
</block>
<block name="main">
    <table class="table table-hover mt20">
        <tr>
            <td>订单ID</td>
            <td>订单编号</td>
            <td>用户id</td>
            <td>送货地址</td>
            <td>收货人</td>
            <td>电话</td>
            <td>总价</td>
            <td>下单时间</td>
            <td>付款方式</td>
            <td>发货状态</td>
            <td>支付状态</td>
            <td>取消状态</td>
            <td>操作</td>
        </tr>
        <foreach name="list" item="v">
        <tr>
            <td><{$v.id}></td>
            <td><{$v.ordernum}></td>
            <td><{$v.uid}></td>
            <td><{$v.address}></td>
            <td><{$v.receiver}></td>
            <td><{$v.tel}></td>
            <td><{$v.price}>元</td>
            <td><{$v.otime}></td>
            <td>
                <if condition="$v.paytype eq '1'">在线付款
                <elseif condition="$v.paytype eq '2'"/>货到付款
                </if>
            </td>
            <td class="sendstatus">
                <if condition="$v.sendstatus eq '0'">
                <a class="link"><span class="no0">未发货</span></a>
                <elseif condition="$v.sendstatus eq '1'"/>
                <a class="link"><span class="no1">已发货</span></a>
                <else />
                <a class="link"><span class="no2">已签收</span></a>
                </if>
            </td>
            <td class="paystatus">
                <if condition="$v.paystatus eq '0'">
                <a class="link"><span class="no0">未支付</span></a>
                <elseif condition="$v.paystatus eq '1'"/>
                <a class="link"><span class="no1">已支付</span></a>
                </if>
            </td>
            <td class="cancle">
                <if condition="$v.cancle eq '0'">
                <a class="link"><span class="no0">取消订单</span></a>
                <elseif condition="$v.cancle eq '1'"/>
                <a class="link"><span class="no1">未取消</span></a>
                </if>
            </td>
            <td class="col-md-2">
                <a href="<{:U('del',array('id'=>$v['id']))}>" class="btn btn-danger">删除</a>
            </td>
        </tr>
        </foreach>
    </table>
    <a href="<{:U('Order/edit')}>" class="url"></a>
    <script src="__PUBLIC__/Js/jquery-2.1.4.min.js"></script>
    <script>
        $('.link').click(function(){
            var oid = $(this).parent().siblings().first().html();//订单id
            var type = $(this).parent().attr('class');//列名
            var val = $(this).children().attr('class');//遍历出来的中文状态
            var inp = $(this).children();//整个span标签
            var num = 0;//计数
            var snum = 0;//计数
            var value = '';//中文值
            var url = $('.url').attr('href');//ajax传递连接
            var url2 = url+"?num="+num+"&type="+type+"&id="+oid;
            console.log(url2);
            // console.log($(this).children());
            
            // console.log(url);
            //翻译/控制取值范围
            if(type=='sendstatus'){
                if (val == 'no2') {
                    num = 2;
                    inp.attr("class","no3");
                }else if(val == 'no1'){
                    num = 1;
                    inp.attr("class","no2");
                }else if(val == 'no0'){
                    num = 0;
                    inp.attr("class","no1");
                }else if(val == 'no3'){
                    inp.attr("class","no0");
                    num = 0;
                }
            }else{
                if(val == 'no1'){
                    num = 1;
                    inp.attr("class","no0");
                }else if(val == 'no0'){
                    num = 0;
                    inp.attr("class","no1");
                }else if(val == 'no2'){
                    inp.attr("class","no0");
                    num = 0;
                }
            }
            //翻译
            switch (type) {
            case 'sendstatus':
                if(num == 0){
                    value = '已发货';
                }else if (num == 1) {
                    value = '已签收';
                }else if (num == 2) {
                    value = '未发货';
                }
                break;
            case 'paystatus':
                if(num == 0){
                    value = '已支付';
                }else if (num == 1) {
                    value = '未支付';
                }
                break;
            case 'cancle':
                if(num == 0){
                    value = '未取消';
                }else if (num == 1) {
                    value = '取消订单';
                }
                break;
            }
            // console.log(inp);
            // console.log(value);
            // val.html(value);

            $.ajax({
                type:'get',
                url:url+"?num="+num+"&type="+type+"&id="+oid,
                success:function(data){
                    console.log(1);
                    // console.log(data);
                    // alert(1);
                    inp.html(value);
                },
                error:function(data){
                    console.log(2);
                    // console.log(data);
                    inp.html(value);
                    inp.attr("class","no"+(num+1));
                },
                dataType:"json",
            })
        })
    </script>
</block>
